package com.sofwin.configer;

import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

/**
 * @packageName: com.sofwin.configer
 * @user: andyliu
 * @date: 2023/5/10 16:08
 * @email 115176513@qq.com
 * @description: web.xml
 */

public class WebConfiger extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{RootConfiger.class,MybatisConfiger.class,ShiroConfiger.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{MvcConfiger.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }

//    @Override
//    protected FilterRegistration.Dynamic registerServletFilter(ServletContext servletContext, Filter filter) {
//        DelegatingFilterProxy filterProxy = new DelegatingFilterProxy();
//        filterProxy.setTargetFilterLifecycle(true);
//        FilterRegistration.Dynamic shiroFilter = servletContext.addFilter("shiroFilter", filterProxy);
//        shiroFilter.addMappingForUrlPatterns(null,true,"/*");
//        return shiroFilter;
//    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        super.onStartup(servletContext);
        DelegatingFilterProxy filterProxy = new DelegatingFilterProxy();
        filterProxy.setTargetFilterLifecycle(true);
        servletContext.addFilter("shiroFilter",filterProxy).addMappingForUrlPatterns(null,true,"/*");
    }
}
